﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Controls="clr-namespace:PSE.Framework.UI.Controls.SmartClient;assembly=PSE.Framework.UI.Controls">

    <Style TargetType="{x:Type Controls:ContextMenu}">
        <Setter Property="Width" Value="Auto"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Controls:ContextMenu}">
                    <Border Background="{DynamicResource BrushContextMenuBackground}" CornerRadius="11" BorderBrush="{DynamicResource BrushContextMenuBorder}" BorderThickness="2" Width="{TemplateBinding Width}" VerticalAlignment="Stretch">
                        <Grid Margin="0,8,0,8">
                            <StackPanel IsItemsHost="True" Margin="0,0,0,0" KeyboardNavigation.DirectionalNavigation="Cycle" KeyboardNavigation.TabNavigation="Cycle"/>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type Controls:ContextMenuItem}">
        <Setter Property="CausesValidation" Value="False"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Controls:ContextMenuItem}">
                    <Border x:Name="Border" Margin="0,0,0,0">
                        <Grid Height="25" Margin="5,0,15,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="15"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="10"/>
                            </Grid.ColumnDefinitions>
                            <!--Alterado de forma a utilizar ContentPresenter ao invés de um Image para se adequar ao estilo padrão do MenuItem-->
                            <ContentPresenter x:Name="Icon" Grid.Column="0" Width="13" Height="13" VerticalAlignment="Center" ContentSource="Icon"/>
                            <TextBlock Grid.Column="1" x:Name="TextBlock" Padding="0" Foreground="{DynamicResource BrushContextMenuItemForeground}" Text="{TemplateBinding Header}" VerticalAlignment="Center" Style="{DynamicResource ControlFont}" Margin="6,0,0,0" TextTrimming="CharacterEllipsis" ToolTip="{TemplateBinding Header}"/>
					        <Popup x:Name="PART_Popup" IsOpen="{Binding Path=IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" Focusable="false" AllowsTransparency="true" Placement="Right" PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}" VerticalOffset="-1">
                                <Border Background="Transparent">
						            <Border x:Name="SubMenuBorder" CornerRadius="11" Background="{DynamicResource BrushContextMenuBackground}" BorderBrush="{DynamicResource BrushContextMenuBorder}" BorderThickness="2" Width="{TemplateBinding Width}" VerticalAlignment="Stretch">
							            <ScrollViewer Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}" CanContentScroll="true">
								            <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Grid.IsSharedSizeScope="true" KeyboardNavigation.DirectionalNavigation="Cycle" KeyboardNavigation.TabNavigation="Cycle" Margin="0,8,0,8"/>
							            </ScrollViewer>
						            </Border>
                                </Border>
					        </Popup>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Background" Value="{DynamicResource BrushContextMenuItemBackgroundHover}" TargetName="Border"/>
                        </Trigger>
                        <Trigger Property="IsFocused" Value="True">
                            <Setter Property="Background" Value="{DynamicResource BrushContextMenuItemBackgroundHover}" TargetName="Border"/>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Foreground" Value="{DynamicResource BrushContextMenuItemForegroundDisabled}" TargetName="TextBlock"/>
                        </Trigger>
                        <Trigger Property="ContextMenuItemIcon" Value="IconContextMenuNone">
                            <Setter Property="Width" Value="5" TargetName="Icon"/>
                            <Setter Property="Height" Value="5" TargetName="Icon"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="ContextMenuItemHelp" TargetType="{x:Type MenuItem}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="MenuItem">
                    <Border x:Name="Border" BorderThickness="{TemplateBinding Border.BorderThickness}" BorderBrush="{TemplateBinding Border.BorderBrush}" Background="{TemplateBinding Panel.Background}" SnapsToDevicePixels="True">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" MinWidth="17" SharedSizeGroup="MenuItemIconColumnGroup" />
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" SharedSizeGroup="MenuItemIGTColumnGroup" />
                                <ColumnDefinition Width="14" />
                            </Grid.ColumnDefinitions>
                            <ContentPresenter Content="{TemplateBinding MenuItem.Icon}" ContentSource="Icon" x:Name="Icon" Margin="4,0,6,0" VerticalAlignment="Center" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
                            <Path Fill="{TemplateBinding TextElement.Foreground}" x:Name="GlyphPanel" FlowDirection="LeftToRight" Margin="4,0,6,0" VerticalAlignment="Center" Visibility="Hidden">
                                <Path.Data>
                                    <PathGeometry Figures="M0,2L0,4.8L2.5,7.4L7.1,2.8L7.1,0L2.5,4.6z" />
                                </Path.Data>
                            </Path>
                            <ContentPresenter RecognizesAccessKey="True" Content="{TemplateBinding HeaderedContentControl.Header}" ContentTemplate="{TemplateBinding HeaderedContentControl.HeaderTemplate}" ContentStringFormat="{TemplateBinding HeaderedItemsControl.HeaderStringFormat}" ContentSource="Header" Margin="{TemplateBinding Control.Padding}" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" Grid.Column="1" />
                            <TextBlock x:Name="TextBlock" Text="{TemplateBinding MenuItem.InputGestureText}" ToolTip="{TemplateBinding MenuItem.InputGestureText}" Margin="5,2,0,2" Grid.Column="2" DockPanel.Dock="Right" Style="{DynamicResource ControlFont}" />
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="Icon" Value="x:Null">
                            <Setter Property="Visibility" TargetName="Icon" Value="Collapsed" />
                        </Trigger>
                        <Trigger Property="IsChecked" Value="True">
                            <Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible" />
                            <Setter Property="Visibility" TargetName="Icon" Value="Collapsed" />
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Background" Value="{DynamicResource BrushContextMenuItemBackgroundHover}" TargetName="Border"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type Controls:ContextMenuItemSeparator}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Controls:ContextMenuItemSeparator}">
                    <StackPanel x:Name="StackPanel" Orientation="Vertical" HorizontalAlignment="Stretch" Height="2" Margin="0,2.5,0,2.5">
                        <Rectangle x:Name="Separator" Height="2" Fill="{DynamicResource BrushMenuSeparator}" Visibility="{Binding SeparatorVisibility}"/>
                    </StackPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>
